
#ifndef NL_MISC_STRING_SPLITER_H
#define NL_MISC_STRING_SPLITER_H

#include <nel/misc/algo.h>

namespace NLMISC
{

class CStringSpliter
{
private:
	std::vector<std::string> fields;
	std::string delims;
	std::string string_null;

	void CStringSpliter::split(std::string& line)
	{
		NLMISC::splitString( line, delims, fields );
	}
public:
//	static 
public:
	CStringSpliter():delims (""),string_null(""){}
	CStringSpliter(std::string ndelims):delims (ndelims),string_null(""){}
	~CStringSpliter(){}

	void CStringSpliter::setDelimiter(std::string s)
	{
		delims=s;
	}

	bool CStringSpliter::splitString(std::string& line)
	{
		if(line.empty()){
			return false;
		}
		split(line);
		return true;
	}

	inline int size(){ return fields.size(); }

	std::string& CStringSpliter::getStr( int idx )
	{
		if( size() > idx  )
			return fields[idx];
		else
			return string_null;
	}

	sint32  CStringSpliter::getInt32( int idx )
	{
		if( size() > idx  )
			return atoi(fields[idx].c_str());
		else
		{
			return std::numeric_limits<sint32>::max();
		}
	}

	sint64  CStringSpliter::getInt64( int idx )
	{
		sint64 iData = std::numeric_limits<sint64>::max();

		if( size() > idx  )
			sscanf( fields[idx].c_str(), "%"NL_I64"d", &iData );

		return iData;
	}

};


}

#endif
